package cool.zhoujie.address.viewmodel;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import androidx.navigation.Navigation;

import java.util.List;
import cool.zhoujie.address.R;
import cool.zhoujie.address.db.Address;
import cool.zhoujie.address.db.AddressDao;
import cool.zhoujie.address.db.AddressDatabase;

public class ShowFragmentViewModel extends ViewModel {

    public MutableLiveData<List<Address>> mList = new MutableLiveData<>();

    public List<Address> list;

    public AddressDao mDao;

    public ShowFragmentViewModel() {
        mDao = AddressDatabase.getInstance().mAddressDao();
        list = mDao.queryAll();
        mList.setValue(list);
    }

    public void navigate(View view) {
        Navigation.findNavController(view).navigate(R.id.action_showFragment_to_newFragment);
    }

    public void navigateToEdit(View view, Address address) {
        Log.d("TAG", "navigateToEdit: ");
        Bundle bundle = new Bundle();
        bundle.putSerializable("address", address);
        Navigation.findNavController(view).navigate(R.id.action_showFragment_to_editFragment, bundle);
    }

}
